package com.seb.cc.gtou.adapter;

import java.util.Date;
import java.text.DateFormat;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView; 

import com.seb.cc.gtou.db.GTSejourDB;
import com.seb.cc.ttou.R;

public class GTouSejourAdapter extends CursorAdapter {
	 private final LayoutInflater mInflater;
	 
	public GTouSejourAdapter(Context context, Cursor c, boolean autoRequery) {
		super(context, c, autoRequery);
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		TextView sejourDesc=(TextView)view.findViewById(R.id.textViewRowDesc);
		sejourDesc.setText(cursor.getString(cursor.getColumnIndex(GTSejourDB.GTSejourTable.DESCRIPTION)));
		TextView startLabel = (TextView)view.findViewById(R.id.textViewLabelDebut);
		startLabel.setText(R.string.sejourListRowFrom);
		
		Date dateDebut = new Date(cursor.getLong(cursor.getColumnIndex(GTSejourDB.GTSejourTable.DATE_DEBUT)));
		
		TextView sejourDebut = (TextView)view.findViewById(R.id.textViewRowDebut);
		DateFormat formatD = DateFormat.getDateInstance (DateFormat.MEDIUM);
		sejourDebut.setText(formatD.format(dateDebut));
		
		TextView endLabel = (TextView)view.findViewById(R.id.textViewLabelFin);
		endLabel.setText(R.string.sejourListRowTo);
		
		Date dateFin = new Date(cursor.getLong(cursor.getColumnIndex(GTSejourDB.GTSejourTable.DATE_FIN)));
		TextView sejourFin = (TextView)view.findViewById(R.id.textViewRowFin);
				
		sejourFin.setText(formatD.format(dateFin));

	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
	      final View view = mInflater.inflate(R.layout.gtousejourrow, parent, false);
	      return view;
	}

}
